﻿using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.DataSourcesRaster;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.SpatialAnalyst;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ArcEngine.CourseDesign.Win.Util
{
    public class RasterOperate
    {
        public static void Clip(IRasterLayer rasterLayer, IFeature feature, string fileFullName)
        {
            try
            {
                IGeoDataset inGeodataset = rasterLayer as IGeoDataset;
                IExtractionOp extractionOp = new RasterExtractionOpClass();
                IEnvelope envelope = feature.Shape.Envelope;
                IGeoDataset outGeodataset = extractionOp.Rectangle(inGeodataset, envelope, true);
                IRaster raster = (IRaster)outGeodataset;
                ISaveAs saveAs = raster as ISaveAs;
                saveAs.SaveAs(fileFullName, null, "TIFF");
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
    }
}
